package com.example.fbztest_vue.controller;

import com.example.fbztest_vue.entity.Position;
import com.example.fbztest_vue.entity.PositionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@Slf4j
@RequestMapping("/api/position")
public class PositionController {

    @Autowired
    PositionMapper positionMapper;

    @GetMapping("getPosition")
    public HashMap<String,Object> get(){
        log.info("请求:{}","get");
        HashMap<String ,Object> map=new HashMap<>();
        Position position=positionMapper.selectByPrimaryKey("1");
        log.info("请求所得:{}",position);
        map.put("position",position);
        return map;
    }

    @PostMapping("newPosition")
    public HashMap<String,Object> newPosition(@RequestBody Position dposition){
        log.info("刷新位置");
        HashMap<String,Object> map=new HashMap<>();
        Position position=positionMapper.selectByPrimaryKey("1");
        position.setX(position.getX()+dposition.getX());
        position.setY(position.getY()+dposition.getY());
        positionMapper.updateByPrimaryKeySelective(position);
        Position position2=positionMapper.selectByPrimaryKey("1");
        map.put("position",position2);
        return map;
    }
}
